<template>
	<view>
		<u-upload ref="upload" :action="fileUploadURL" :file-list="fileList"
			:header="{Authorization:header,operatorid:configOperatorid,Terminal:'WX'}" @on-success="uploadSuccess" @on-error="uploadError"
			@on-remove="removePhoto" @on-progress="changePhoto" :show-progress="false" :max-count="maxCount"
			:max-size="5 * 1024 * 1024" width="140" height="140">
		</u-upload>
	</view>
</template>

<script>
	import {
		mapState,
		mapGetters,
		mapActions
	} from 'vuex';
	import config from '@/common/config.js'
	
	export default {
		name:"common-upload",
		props:{
			maxCount:{
				type:[String,Number],
				default: 9
			}
		},
		data() {
			return {
				fileUploadURL: getApp().globalData.fileUploadURL,
				fileList: [],
				configOperatorid: config.operatorid
			};
		},
		computed: {
			...mapState({
				header: state => state.Authorization,
				Authorization: state => state.Authorization,
				userdetail: state => state.userdetail,
			})
		},
		methods:{
			// 图片上传
			uploadSuccess(data, index, lists, name) {
				uni.hideLoading()
				// this.showUploadList = false
				if (data.status == 2) {
					this.$refs.upload.clear()
					// uni.showModal({
					// 	title: '提示',
					// 	content: '请先登录再上传图片',
					// 	success: (res) => {
					// 		if (res.confirm) {
					// 			this.isWechat = true
					// 		}
					// 	}
					// })
					return
				}
				// this.order.pics.push(data.datas.path);
				
				this.$emit('on-success',data, index, lists, name)
			},
			removePhoto(index, lists, name) {
				this.fileList.splice(index, 1)
				// this.order.pics.splice(index, 1)
				
				this.$emit('@on-remove',index, lists, name)
			},
			changePhoto(res) {
				console.log(res)
				uni.showLoading({
					title: res.progress + '%'
				})
			},
			uploadError(data, index, lists, name) {
				uni.hideLoading()
				uni.showToast({
					title: '提交失败，请重试'
				})
				
				this.$emit("on-error",data, index, lists, name)
			},
		}
	}
</script>

<style>

</style>